import { API_LIST } from '../../../Api/Api'
import { commonTableList } from '../Common/common'
import { AddDataButton, ModDataButton, DelDataButton, OpenTwoRouter } from '../Common/options'
import { TestCategory, LabDataSource } from '../Common/Conversion'

export const TestType = async ({ url, OptionsEvent, Permission, actionRef }) => {
    const testCategoryUuid = await TestCategory()
    const labDataSourceUuid = await LabDataSource()
    let data = {
        type: '试验事务',
        pageSize: 10,
        params: { pageIndex: 1, OrderField: 'testCategory.code@asc,code@asc' },
        get: API_LIST()[`get${url}`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        options: [
            Permission.findIndex(v => v.uuid === '5639b747-d0aa-4723-97a5-34110a097771') !== -1 && (
                <AddDataButton OptionsEvent={OptionsEvent} type="primary" icon="add" title="新增" />
            ),
        ],
        columns: [
            commonTableList.uuid,
            {
                ...commonTableList.code,
                rules: true,
                hideInSearch: true,
                render: (_, { testCategory, code }) => (
                    <div>
                        {' '}
                        {testCategory.code}-{code}{' '}
                    </div>
                ),
            },
            {
                dataIndex: 'testCategoryUuid',
                title: '试验类别',
                valueType: 'select',
                valueEnum: testCategoryUuid,
                rules: true,
                width: 350,
            },
            {
                dataIndex: 'tableName',
                title: '参数简称',
                valueType: 'input',
                rules: true,
                width: 200,
            },
            {
                dataIndex: 'fullName',
                title: '参数全称',
                valueType: 'input',
                rules: true,
                width: 400,
                hideInSearch: true,
            },
            {
                dataIndex: 'labDataSourceUuid',
                title: '数据来源',
                valueType: 'select',
                rules: true,
                width: 200,
                hideInSearch: true,
                valueEnum: labDataSourceUuid,
            },
            {
                dataIndex: 'responsor',
                title: '检测负责人',
                valueType: 'input',
                search: true,
                width: 150,
            },
            { ...commonTableList.isEnabled, rules: true },
            { ...commonTableList.sortId, rules: true, hideInSearch: true },
            commonTableList.remark,
            commonTableList.createUserName,
            commonTableList.createTime,
            commonTableList.updateUserName,
            commonTableList.updateTime,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 240,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    return [
                        Permission.findIndex(v => v.uuid === '643e769f-a90d-4c2c-9f5f-c394654401cc') !== -1 && (
                            <ModDataButton OptionsEvent={OptionsEvent} key="modify" title="修改" data={record} />
                        ),
                        Permission.findIndex(v => v.uuid === 'aede555e-2476-45c3-8807-46d6b55ebaa2') !== -1 && (
                            <OpenTwoRouter
                                key="TwoOne"
                                title="摄像头列表"
                                modal="TableList"
                                OptionsEvent={OptionsEvent}
                                other={{
                                    page: 'TestType',
                                    Permission,
                                    oneData: record,
                                    header: data.columns,
                                }}
                            />
                        ),
                        Permission.findIndex(v => v.uuid === 'cbbd3461-e684-4e0a-8619-1818dee38e9a') !== -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url={url}
                                uuid={record.uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }
    return data
}
